package com.pengtu.service.business;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.jbpm.api.history.HistoryTask;
import org.jbpm.api.task.Task;
import org.jbpm.pvm.internal.task.TaskImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.pengtu.entity.admin.Convey;
import com.pengtu.entity.admin.Received;
import com.pengtu.entity.app.User;
import com.pengtu.entity.contract.Document;
import com.pengtu.entity.human.Leave;
import com.pengtu.entity.project.ProjectInfo;
import com.pengtu.entity.receive.Entrust;
import com.pengtu.entity.trial.Order;
import com.pengtu.model.HomeModel;
import com.pengtu.model.PersonalModel;
import com.pengtu.service.JbpmTemplateManager;
import com.pengtu.service.admin.ConveyaManager;
import com.pengtu.service.admin.ReceivedManager;
import com.pengtu.service.contract.AccordingManager;
import com.pengtu.service.human.LeaveOvertimeManager;
import com.pengtu.service.project.ProjectManager;
import com.pengtu.service.receive.TrialCommonManager;
import com.pengtu.service.trial.TrialManager;

@Component
@Transactional
public class HomeManager {
	private JbpmTemplateManager jbpmTemplateManager;
	private LeaveOvertimeManager leaveOvertimeManager;
	private ConveyaManager conveyaManager;
	private ReceivedManager receivedManager;
	private AccordingManager accordingManager;
	private ProjectManager projectManager;
	private TrialManager trialManager;
	private TrialCommonManager trialCommonManager;

	/**
	 * @param projectManager
	 *            the projectManager to set
	 */
	@Autowired
	public void setProjectManager(ProjectManager projectManager) {
		this.projectManager = projectManager;
	}

	/**
	 * @param accordingManager
	 *            the accordingManager to set
	 */
	@Autowired
	public void setAccordingManager(AccordingManager accordingManager) {
		this.accordingManager = accordingManager;
	}

	@Autowired
	public void setJbpmTemplateManager(JbpmTemplateManager jbpmTemplateManager) {
		this.jbpmTemplateManager = jbpmTemplateManager;
	}

	/**
	 * @param leaveOvertimeManager
	 *            the leaveOvertimeManager to set
	 */
	@Autowired
	public void setLeaveOvertimeManager(
			LeaveOvertimeManager leaveOvertimeManager) {
		this.leaveOvertimeManager = leaveOvertimeManager;
	}

	/**
	 * @param conveyaManager
	 *            the conveyaManager to set
	 */
	@Autowired
	public void setConveyaManager(ConveyaManager conveyaManager) {
		this.conveyaManager = conveyaManager;
	}

	/**
	 * @param receivedManager
	 *            the receivedManager to set
	 */
	@Autowired
	public void setReceivedManager(ReceivedManager receivedManager) {
		this.receivedManager = receivedManager;
	}

	/**
	 * @param trialManager
	 *            the trialManager to set
	 */
	@Autowired
	public void setTrialManager(TrialManager trialManager) {
		this.trialManager = trialManager;
	}

	/**
	 * @param trialCommonManager
	 *            the trialCommonManager to set
	 */
	@Autowired
	public void setTrialCommonManager(TrialCommonManager trialCommonManager) {
		this.trialCommonManager = trialCommonManager;
	}

	/**
	 * 我的代办列表 find: 适用:
	 * 
	 * @param user
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public List<HomeModel> find(User user) {
		List<HomeModel> list = new ArrayList<HomeModel>();
		List<HomeModel> homes1 = this.findGroupTasks(user);
		List<HomeModel> homes2 = this.findPersonalTasks(user);
		if (homes1.size() != 0 || homes1 != null) {
			for (HomeModel homeModel : homes1) {
				list.add(homeModel);
			}
		}
		if (homes2.size() != 0 || homes2 != null) {
			for (HomeModel homeModel : homes2) {
				list.add(homeModel);
			}
		}
		return list;
	}

	/**
	 * 流程中的待办任务 findPersonalTasks: 适用:
	 * 
	 * @param user
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public List<HomeModel> findPersonalTasks(User user) {
		/*
		 * List<HomeModel> list = new ArrayList<HomeModel>(); List<Task>
		 * taskList = jbpmTemplateManager.findPersonalTasks(user
		 * .getUserName()); for (Task task : taskList) { HomeModel homeModel =
		 * new HomeModel(); String taskId = task.getId(); String exectionId =
		 * task.getExecutionId(); String[] arg = exectionId.split("\\."); String
		 * str = arg[0]; if ("labs".equals(str)) { String id = (String)
		 * jbpmTemplateManager.getVariableByTaskId( taskId, Constants.LABS_ID);
		 * FlowLabsFiling entity = labsFilingManager.getFlowLabsFiling(id); if
		 * (entity != null) { ProjectInfo projInfo =
		 * projectManager.getProj("id", entity .getProjectInfo().getId());
		 * homeModel = this.setHomeModel(exectionId, task, entity.getOrgId(),
		 * entity.getAcceptionDate(), entity.getPrepareDate(), entity.getId(),
		 * projInfo, "1"); list.add(homeModel); } } else if
		 * ("apply".equals(str)) { String id = (String)
		 * jbpmTemplateManager.getVariableByTaskId( taskId, Constants.APPLY_ID);
		 * FlowApplication flowApplication = applicationManager
		 * .getFlowApplication(id); if (flowApplication != null) { ProjectInfo
		 * projectInfo = projectManager.getProj("id",
		 * flowApplication.getProjectInfo().getId()); homeModel =
		 * this.setHomeModel(exectionId, task, flowApplication.getOrgId(),
		 * flowApplication.getAcceptionDate(), flowApplication.getPrepareDate(),
		 * flowApplication.getId(), projectInfo, "0"); list.add(homeModel); } }
		 * else if ("detection".equals(str)) { String id = (String)
		 * jbpmTemplateManager.getVariableByTaskId( taskId,
		 * Constants.DETECTION_ID); FlowDetection entity =
		 * flowDetectionManager.getFlowDetection(id); if (null != entity) {
		 * ProjectInfo projectInfo = projectManager.getProj("id",
		 * entity.getProjectInfo().getId()); homeModel =
		 * this.setHomeModel(exectionId, task, entity.getOrgId(),
		 * entity.getAcceptionDate(), entity.getPrepareDate(), entity.getId(),
		 * projectInfo, "0"); list.add(homeModel); } } else if
		 * ("accept".equals(str)) { String id = (String)
		 * jbpmTemplateManager.getVariableByTaskId( taskId,
		 * Constants.ACCEPT_ID); FlowAcceptance entity =
		 * flowAcceptanceManager.getFlowAcceptance(id); if (null != entity) {
		 * ProjectInfo projectInfo = projectManager.getProj("id",
		 * entity.getProjectInfo().getId()); homeModel =
		 * this.setHomeModel(exectionId, task, entity.getOrgId(),
		 * entity.getAcceptionDate(), entity.getPrepareDate(), entity.getId(),
		 * projectInfo, "0"); list.add(homeModel); } } else if
		 * ("comple".equals(str)) { String id = (String)
		 * jbpmTemplateManager.getVariableByTaskId( taskId,
		 * Constants.COMPLE_ID); FlowCompletion entity =
		 * completionManager.getFlowCompletion(id); if (null != entity) {
		 * ProjectInfo projectInfo = projectManager.getProj("id",
		 * entity.getProjectInfo().getId()); homeModel =
		 * this.setHomeModel(exectionId, task, entity.getOrgId(),
		 * entity.getAcceptionDate(), entity.getPrepareDate(), entity.getId(),
		 * projectInfo, "0"); list.add(homeModel); } } }
		 */
		return null;
	}

	/**
	 * 流程中 findGroupTasks: 适用:
	 * 
	 * @param user
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public List<HomeModel> findGroupTasks(User user) {
		// List<HomeModel> list = new ArrayList<HomeModel>();
		// List<Task> taskList = jbpmTemplateManager.findGroupTasks(user);
		// for (Task task : taskList) {
		// HomeModel homeModel = new HomeModel();
		// String taskId = task.getId();
		// String exectionId = task.getExecutionId();
		// String[] arg = exectionId.split("\\.");
		// String str = arg[0];
		// if ("labs".equals(str)) {
		// String id = (String) jbpmTemplateManager.getVariableByTaskId(
		// taskId, Constants.LABS_ID);
		// FlowLabsFiling entity = labsFilingManager.getFlowLabsFiling(id);
		// if (entity != null) {
		// ProjectInfo projInfo = projectManager.getProj("id", entity
		// .getProjectInfo().getId());
		// homeModel = this.setHomeModel(exectionId, task,
		// entity.getOrgId(), entity.getAcceptionDate(),
		// entity.getPrepareDate(), entity.getId(), projInfo,
		// "1");
		// list.add(homeModel);
		// }
		// } else if ("apply".equals(str)) {
		// String id = (String) jbpmTemplateManager.getVariableByTaskId(
		// taskId, Constants.APPLY_ID);
		// FlowApplication flowApplication = applicationManager
		// .getFlowApplication(id);
		// if (flowApplication != null) {
		// ProjectInfo projectInfo = projectManager.getProj("id",
		// flowApplication.getProjectInfo().getId());
		// homeModel = this.setHomeModel(exectionId, task,
		// flowApplication.getOrgId(),
		// flowApplication.getAcceptionDate(),
		// flowApplication.getPrepareDate(),
		// flowApplication.getId(), projectInfo, "0");
		// list.add(homeModel);
		// }
		// } else if ("detection".equals(str)) {
		// String id = (String) jbpmTemplateManager.getVariableByTaskId(
		// taskId, Constants.DETECTION_ID);
		// FlowDetection entity = flowDetectionManager.getFlowDetection(id);
		// if (null != entity) {
		// ProjectInfo projectInfo = projectManager.getProj("id",
		// entity.getProjectInfo().getId());
		// homeModel = this.setHomeModel(exectionId, task,
		// entity.getOrgId(), entity.getAcceptionDate(),
		// entity.getPrepareDate(), entity.getId(),
		// projectInfo, "0");
		// list.add(homeModel);
		// }
		// } else if ("accept".equals(str)) {
		// String id = (String) jbpmTemplateManager.getVariableByTaskId(
		// taskId, Constants.ACCEPT_ID);
		// FlowAcceptance entity = flowAcceptanceManager.getFlowAcceptance(id);
		// if (null != entity) {
		// ProjectInfo projectInfo = projectManager.getProj("id",
		// entity.getProjectInfo().getId());
		// homeModel = this.setHomeModel(exectionId, task,
		// entity.getOrgId(), entity.getAcceptionDate(),
		// entity.getPrepareDate(), entity.getId(),
		// projectInfo, "0");
		// list.add(homeModel);
		// }
		// } else if ("comple".equals(str)) {
		// String id = (String) jbpmTemplateManager.getVariableByTaskId(
		// taskId, Constants.COMPLE_ID);
		// FlowCompletion entity = completionManager.getFlowCompletion(id);
		// if (null != entity) {
		// ProjectInfo projectInfo = projectManager.getProj("id",
		// entity.getProjectInfo().getId());
		// homeModel = this.setHomeModel(exectionId, task,
		// entity.getOrgId(), entity.getAcceptionDate(),
		// entity.getPrepareDate(), entity.getId(),
		// projectInfo, "0");
		// list.add(homeModel);
		// }
		// }
		// }
		return null;
	}

	public HomeModel setHomeModel(String exectionId, Task task, String orgId,
			Date acceptionDate, Date prepareDate, String key,
			ProjectInfo projectInfo, String labs) {
		HomeModel homeModel = new HomeModel();
		homeModel.setExectionId(exectionId);
		homeModel.setTaskId(task.getId());
		homeModel.setStatus(projectInfo.getStatus());
		homeModel.setAcceptionDate(acceptionDate);
		homeModel.setProjId(projectInfo.getId());
		homeModel.setKey(key);
		homeModel.setOrgId(orgId);
		homeModel.setPrepareDate(prepareDate);
		homeModel.setLabs(labs);
		homeModel.setTask(task);
		return homeModel;
	}

	/**
	 * 待办任务 findTask: 适用:首页待办事宜
	 * 
	 * @param user
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public List<TaskImpl> findTask(User user) {
		List<TaskImpl> list = new ArrayList<TaskImpl>();
		List<Task> tasks1 = jbpmTemplateManager.findGroupTasks(user);
		List<Task> tasks2 = jbpmTemplateManager.findPersonalTasks(user
				.getUserName());
		if (tasks1.size() != 0 || tasks1 != null) {
			for (Task task : tasks1) {
				list.add((TaskImpl) task);
			}
		}
		if (tasks2.size() != 0 || tasks2 != null) {
			for (Task task : tasks2) {
				list.add((TaskImpl) task);
			}
		}
		return list;
	}

	/**
	 * 根据Task表得到业务 getObject: 适用:
	 * 
	 * @param id
	 * @param key
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public PersonalModel getObject(String id, String key) {
		if (StringUtils.equals(key, "convey")) {
			PersonalModel personalModel = new PersonalModel();
			Convey convey = conveyaManager.get(id);
			personalModel.setStatus(convey.getStatus());
			personalModel.setType("公文管理");
			personalModel.setTitle("发文-" + convey.getTitle());
			return personalModel;
		}
		if (StringUtils.equals(key, "oconvey")) {
			PersonalModel personalModel = new PersonalModel();
			Convey convey = conveyaManager.get(id);
			personalModel.setStatus(convey.getStatus());
			personalModel.setType("公文管理");
			personalModel.setTitle("项目发文-" + convey.getTitle());
			return personalModel;
		}
		if (StringUtils.equals(key, "received")) {
			PersonalModel personalModel = new PersonalModel();
			Received received = receivedManager.get(id);
			personalModel.setStatus(received.getStatus());
			personalModel.setType("公文管理");
			personalModel.setTitle("收文-" + received.getTitle());
			return personalModel;
		}
		// if (StringUtils.equals(key, "apply")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowApplication flowApplication = applicationManager
		// .getFlowApplication(id);
		// personalModel
		// .setProjectId(flowApplication.getProjectInfo().getId());
		// personalModel.setStatus(flowApplication.getStatus());
		// personalModel.setType("质量监督受理");
		// personalModel.setTitle("质量监督申请-"
		// + flowApplication.getProjectInfo().getProjName());
		// return personalModel;
		// }
		if (StringUtils.equals(key, "leave")) {
			PersonalModel personalModel = new PersonalModel();
			Leave leave = leaveOvertimeManager.getLeave(id);
			personalModel.setType("人事管理");
			personalModel.setTitle("请(休)假申请-" + leave.getUserid());
			return personalModel;
		}
		// if (StringUtils.equals(key, "labs")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowLabsFiling flowLabsFiling = labsFilingManager
		// .getFlowLabsFiling(id);
		// personalModel.setProjectId(flowLabsFiling.getProjectInfo().getId());
		// personalModel.setStatus(flowLabsFiling.getStatus());
		// personalModel.setType("质量监督受理");
		// personalModel.setTitle("实验室备案-"
		// + flowLabsFiling.getProjectInfo().getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "mdetect")) {
		// PersonalModel personalModel = new PersonalModel();
		// MiddleDatection middleDatection = middledetectManager
		// .getMiddleDatection(id);
		// personalModel
		// .setProjectId(middleDatection.getProjectInfo().getId());
		// personalModel.setStatus(middleDatection.getStatus());
		// personalModel.setType("质量监督受理");
		// personalModel.setTitle("中间交工检测申请-"
		// + middleDatection.getProjectInfo().getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "dmarine")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowMarine flowMarine = marineDetectManager.getFlowMarine(id);
		// personalModel.setProjectId(flowMarine.getProjectInfo().getId());
		// personalModel.setStatus(flowMarine.getStatus());
		// personalModel.setType("质量监督受理");
		// personalModel.setTitle("水运交工质量鉴定申请-"
		// + flowMarine.getProjectInfo().getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "cmarine")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowMarineCheck flowMarineCheck = marineCheckManager
		// .getFlowCheck(id);
		// personalModel
		// .setProjectId(flowMarineCheck.getProjectInfo().getId());
		// personalModel.setStatus(flowMarineCheck.getStatus());
		// personalModel.setType("质量监督受理");
		// personalModel.setTitle("水运竣工质量核查申请-"
		// + flowMarineCheck.getProjectInfo().getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "detection")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowDetection flowDetection =
		// flowDetectionManager.getFlowDetection(id);
		// personalModel.setProjectId(flowDetection.getProjectInfo().getId());
		// personalModel.setStatus(flowDetection.getStatus());
		// personalModel.setType("质量监督受理");
		// personalModel.setTitle("完工后交工检测申请-"
		// + flowDetection.getProjectInfo().getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "accept")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowAcceptance flowAcceptance =
		// flowAcceptanceManager.getFlowAcceptance(id);
		// personalModel.setProjectId(flowAcceptance.getProjectInfo().getId());
		// personalModel.setStatus(flowAcceptance.getStatus());
		// personalModel.setType("质量监督受理");
		// personalModel.setTitle("交工检测报告申请-"
		// + flowAcceptance.getProjectInfo().getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "comple")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowCompletion flowCompletion = completionManager
		// .getFlowCompletion(id);
		// personalModel.setProjectId(flowCompletion.getProjectInfo().getId());
		// personalModel.setStatus(flowCompletion.getStatus());
		// personalModel.setType("质量监督受理");
		// personalModel.setTitle("竣工质量鉴定申请-"
		// + flowCompletion.getProjectInfo().getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "recheck")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowRecheck flowRecheck = recheckManager.getFlowRecheck(id);
		// personalModel.setProjectId(flowRecheck.getProjectInfo().getId());
		// personalModel.setStatus(flowRecheck.getStatus());
		// personalModel.setType("质量监督受理");
		// personalModel.setTitle("竣工质量复测申请-"
		// + flowRecheck.getProjectInfo().getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "plan")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowPlan flowPlan = planManager.get(id);
		// personalModel.setProjectId(flowPlan.getProjectId());
		// personalModel.setStatus(flowPlan.getStatus());
		// personalModel.setType("日常监督");
		// personalModel.setTitle("编制监督计划-"
		// + projectManager.getProj("id", flowPlan.getProjectId())
		// .getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "check")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowCheck flowCheck = machineManager.get(id);
		// personalModel.setProjectId(flowCheck.getProjectId());
		// personalModel.setStatus(flowCheck.getStatus());
		// personalModel.setType("日常监督");
		// personalModel.setTitle("日常监督检查-"
		// + projectManager.getProj("id", flowCheck.getProjectId())
		// .getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "estimate")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowEstimate flowEstimate = estimateManager.getFlowEstimate(id);
		// personalModel.setProjectId(flowEstimate.getProjectInfo().getId());
		// personalModel.setStatus(flowEstimate.getStatus());
		// personalModel.setType("造价管理");
		// personalModel.setTitle("投资估算-"
		// + projectManager.getProj("id", flowEstimate.getProjectInfo().getId())
		// .getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "budget")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowBudget flowBudget = budgetManager.getFlowBudget(id);
		// personalModel.setProjectId(flowBudget.getProjectInfo().getId());
		// personalModel.setStatus(flowBudget.getStatus());
		// personalModel.setType("造价管理");
		// personalModel.setTitle("初步设计概算-"
		// + projectManager.getProj("id", flowBudget.getProjectInfo().getId())
		// .getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "limited")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowLimited flowLimited = flowLimitedManager.getFlowLimited(id);
		// personalModel.setProjectId(flowLimited.getProjectInfo().getId());
		// personalModel.setStatus(flowLimited.getStatus());
		// personalModel.setType("造价管理");
		// personalModel.setTitle("最高限价审查-"
		// + projectManager.getProj("id", flowLimited.getProjectInfo().getId())
		// .getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "drawing")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowDrawing flowDrawing = flowDrawingManager.getFlowDrawing(id);
		// personalModel.setProjectId(flowDrawing.getProjectInfo().getId());
		// personalModel.setStatus(flowDrawing.getStatus());
		// personalModel.setType("造价管理");
		// personalModel.setTitle("施工图预算审查-"
		// + projectManager.getProj("id", flowDrawing.getProjectInfo().getId())
		// .getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "completed")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowCompleted flowCompleted =
		// flowCompletedManager.getFlowCompleted(id);
		// personalModel.setProjectId(flowCompleted.getProjectInfo().getId());
		// personalModel.setStatus(flowCompleted.getStatus());
		// personalModel.setType("造价管理");
		// personalModel.setTitle("竣工决算审查-"
		// + projectManager.getProj("id",
		// flowCompleted.getProjectInfo().getId())
		// .getProjName());
		// return personalModel;
		// }
		// if (StringUtils.equals(key, "modify")) {
		// PersonalModel personalModel = new PersonalModel();
		// FlowModify flowModify = flowModifyManager.getFlowModify(id);
		// personalModel.setProjectId(flowModify.getProjectInfo().getId());
		// personalModel.setStatus(flowModify.getStatus());
		// personalModel.setType("造价管理");
		// personalModel.setTitle("设计变更预算审查-"
		// + projectManager.getProj("id", flowModify.getProjectInfo().getId())
		// .getProjName());
		// return personalModel;
		// }
		if (StringUtils.equals(key, "document")) {
			PersonalModel personalModel = new PersonalModel();
			Document document = accordingManager.findDocumentByValue("id", id);
			personalModel.setType("合同管理");
			personalModel.setTitle("合同审核-"
					+ projectManager.getProj("id", document.getPid())
							.getProjName() + "-建设工程检测协议书");
			return personalModel;
		}

		if (StringUtils.equals(key, "order05")) {
			PersonalModel personalModel = new PersonalModel();
			Order order = trialManager.findByOrder("id", id);
			personalModel.setType("试验管理");
			personalModel.setTitle("试验审核-"
					+ order.getEntrust().getRelationship().getProj()
							.getProjName() + "试验检测管理");
			return personalModel;
		}
		
		if (StringUtils.equals(key, "order06")) {
			PersonalModel personalModel = new PersonalModel();
			Order order = trialManager.findByOrder("id", id);
			personalModel.setType("试验管理");
			personalModel.setTitle("试验审核-"
					+ order.getEntrust().getRelationship().getProj()
							.getProjName() + "试验检测管理");
			return personalModel;
		}
		
		if (StringUtils.equals(key, "order07")) {
			PersonalModel personalModel = new PersonalModel();
			Order order = trialManager.findByOrder("id", id);
			personalModel.setType("试验管理");
			personalModel.setTitle("试验审核-"
					+ order.getEntrust().getRelationship().getProj()
							.getProjName() + "试验检测管理");
			return personalModel;
		}
		
		if (StringUtils.equals(key, "order08")) {
			PersonalModel personalModel = new PersonalModel();
			Order order = trialManager.findByOrder("id", id);
			personalModel.setType("试验管理");
			personalModel.setTitle("试验审核-"
					+ order.getEntrust().getRelationship().getProj()
							.getProjName() + "试验检测管理");
			return personalModel;
		}
		
		if (StringUtils.equals(key, "order09")) {
			PersonalModel personalModel = new PersonalModel();
			Order order = trialManager.findByOrder("id", id);
			personalModel.setType("试验管理");
			personalModel.setTitle("试验审核-"
					+ order.getEntrust().getRelationship().getProj()
							.getProjName() + "试验检测管理");
			return personalModel;
		}
		
		if (StringUtils.equals(key, "entrust05")) {
			PersonalModel personalModel = new PersonalModel();
			Entrust entrust = trialCommonManager.FindByProEntrust("id", id);
			personalModel.setType("收样管理");
			personalModel.setTitle("收样复核-"
					+ entrust.getRelationship().getProj()
							.getProjName() + "收样复核");
			return personalModel;
		}
		
		if (StringUtils.equals(key, "entrust06")) {
			PersonalModel personalModel = new PersonalModel();
			Entrust entrust = trialCommonManager.FindByProEntrust("id", id);
			personalModel.setType("收样管理");
			personalModel.setTitle("收样复核-"
					+ entrust.getRelationship().getProj()
							.getProjName() + "收样复核");
			return personalModel;
		}
		
		if (StringUtils.equals(key, "entrust07")) {
			PersonalModel personalModel = new PersonalModel();
			Entrust entrust = trialCommonManager.FindByProEntrust("id", id);
			personalModel.setType("收样管理");
			personalModel.setTitle("收样复核-"
					+ entrust.getRelationship().getProj()
							.getProjName() + "收样复核");
			return personalModel;
		}
		
		if (StringUtils.equals(key, "entrust08")) {
			PersonalModel personalModel = new PersonalModel();
			Entrust entrust = trialCommonManager.FindByProEntrust("id", id);
			personalModel.setType("收样管理");
			personalModel.setTitle("收样复核-"
					+ entrust.getRelationship().getProj()
							.getProjName() + "收样复核");
			return personalModel;
		}
		
		if (StringUtils.equals(key, "entrust09")) {
			PersonalModel personalModel = new PersonalModel();
			Entrust entrust = trialCommonManager.FindByProEntrust("id", id);
			personalModel.setType("收样管理");
			personalModel.setTitle("收样复核-"
					+ entrust.getRelationship().getProj()
							.getProjName() + "收样复核");
			return personalModel;
		}
		return null;
	}

	/**
	 * 得到历史任务列表 getHistoryTasks: 适用:
	 * 
	 * @param user
	 * @return
	 * @exception
	 * @since 1.0.0
	 */
	public List<HistoryTask> getHistoryTasks(User user) {
		return jbpmTemplateManager.getHistoryTaskByAssign(user);
	}

}
